<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:XWord.WPF.ApplicationFramework"
    xmlns:control="clr-namespace:XWord.WPF.ApplicationFramework.Controls">
    <Style TargetType="{x:Type control:EditTextBox}">
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type control:EditTextBox}">
                    <Grid>
                        <Border x:Name="Border_Part" BorderBrush="{TemplateBinding BorderBrush}"  BorderThickness="{TemplateBinding BorderThickness}">
                            <TextBlock x:Name="TextBlock_Part" TextWrapping="Wrap"
                                       Text="{TemplateBinding Text}"></TextBlock>
                        </Border>
                        <Border x:Name="TextBoxBorder_Part"  Visibility="Collapsed" BorderBrush="{TemplateBinding BorderBrush}"  BorderThickness="{TemplateBinding BorderThickness}">
                            <TextBox x:Name="TextBox_Part" BorderThickness="0" TextWrapping="Wrap" 
                                 local:TextBoxService.EnterLine="True"
                                 Text="{Binding Text,RelativeSource={RelativeSource Mode=TemplatedParent},UpdateSourceTrigger=PropertyChanged}"></TextBox>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="TextBlock_Part" Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="Gray"></Setter>
                        </Trigger>
                        <Trigger SourceName="TextBlock_Part" Property="local:UIElementService.IsMouseDown" Value="True">
                            <Setter TargetName="TextBlock_Part" Property="Visibility" Value="Collapsed"></Setter>
                            <Setter TargetName="TextBoxBorder_Part" Property="Visibility" Value="Visible"></Setter>
                            <Setter Property="BorderBrush" Value="Gray"></Setter>
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>

            </Setter.Value>
        </Setter>
    </Style>



</ResourceDictionary>
